package com.wtwd.campus.jdzc.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wtwd.campus.jdzc.dao.JdzcNotificationMapper;
import com.wtwd.campus.jdzc.entity.Notification;
import com.wtwd.campus.jdzc.entity.vo.NotificationVO;
import com.wtwd.campus.jdzc.service.JdzcNotificationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class JdzcNotificationServiceImpl implements JdzcNotificationService {
    @Autowired
    private JdzcNotificationMapper jdzcNotificationMapper;
    @Override
    public Map<String,Object> getNotificationByCondition(NotificationVO data) {
        Page<Notification> page=new Page<>(data.getCurPage(), data.getPageSize());
        IPage<Notification> iPage=jdzcNotificationMapper.getNotificationListByCondition(data,page);
        long total = iPage.getTotal();
        List<Notification> records = iPage.getRecords();
      /*  records.stream().forEach(e->{
            e.setContent(e.getContent().replace("<br/>"," "));
        });*/
        Map<String,Object> result=new HashMap<>();
        result.put("total",total);
        result.put("data",records);
        return result;
    }

    @Override
    public Map<String, Object> getSchoolAndGradeMessByClassId(Integer classes) {
        return jdzcNotificationMapper.getSchoolAndGradeMessByClassId(classes);
    }

    @Override
    public int addNotification(Notification data) {
        return jdzcNotificationMapper.addNotification(data);
    }

    @Override
    public int addNotificationWx(Notification data) {
        return jdzcNotificationMapper.addNotificationWx(data);
    }

    @Override
    public Notification getNotificationById(Integer id) {
        return jdzcNotificationMapper.getNotificationById(id);
    }

    @Override
    public Long getLatestNotificationTimeByClassId(Integer classId) {
        return jdzcNotificationMapper.getLatestNotificationTimeByClassId(classId);
    }

    @Override
    public List<Notification> getNotificationByTimeAndClassId(Integer classId, Long time,Integer count) {
        long end=time+1000*60*60*24;
        Integer min=count*10;
        return jdzcNotificationMapper.getNotificationByTimeAndStuId(classId,time,end,min);
    }
}
